﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using OAuth2.Framework.Resources;

namespace OAuth2.Framework
{
    public static class Errors
    {
        public static OAuthErrorResponseException<T> InvalidRequestException<T> (T context,string parameter,Uri uri=null) where T:class
        {
            if (string.IsNullOrWhiteSpace(parameter)) {
                throw new ArgumentException("parameter");
            }
            if (context == null)
            {
                throw new ArgumentException("context");
            }
            return new OAuthErrorResponseException<T>(context, Parameters.ErrorParameters.ErrorValues.InvalidRequest, string.Format(CultureInfo.CurrentCulture, ErrorResponseResources.InvalidRequest, parameter), errorUri: uri);
        }

        public static OAuthErrorResponseException<T> UnsupportedResponseType<T>(T context, string ResponseType, Uri uri = null) where T : class
        {
            if (string.IsNullOrWhiteSpace(ResponseType))
            {
                throw new ArgumentException("responseType");
            }
            if (context == null)
            {
                throw new ArgumentException("context");
            }

            return new OAuthErrorResponseException<T>(context,
                Parameters.ErrorParameters.ErrorValues.UnsupportedResponseType,
                string.Format(CultureInfo.CurrentCulture, ErrorResponseResources.InvalidResponseType, ResponseType),
                errorUri: uri);
        }

        public static OAuthErrorResponseException<T> AccessDenied<T>(T context) where T : class
        {
            return new OAuthErrorResponseException<T>(context,
                Parameters.ErrorParameters.ErrorValues.AccessDenied,
                description: AuthorizationEndPointResources_CN.ResourceOwnerDenied);
        }
    }
}
